package com.oa.service.impl;

import com.oa.pojo.Party;
import com.oa.service.PartyService;
import com.oa.mapper.PartyMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
* @author 14541
* @description 针对表【party】的数据库操作Service实现
* @createDate 2023-10-27 10:55:55
*/
@Service
public class PartyServiceImpl implements PartyService{
    @Autowired
    private PartyMapper partyMapper;
    @Override
    public List<Party> selectByUserId(Party party){
        return partyMapper.selectByUserId(party);
    }
    @Override
    public int insert(Party party){
        int partyvalue=0;
        Party party1=new Party();
        party1.setId(party.getId());
        List<Party> getP=partyMapper.selectByUserId(party1);
        if(getP.size()>=1){
            partyvalue=-1;
        }else{
            partyvalue=partyMapper.insert(party);
        }
        return partyvalue;
    }

    @Override
    public int update(Party party) {
        int partyvalue=0;
        Party party1=new Party();
        party1.setId(party.getId());
        List<Party> partyList=new ArrayList<>();
        partyList=selectByUserId(party1);
        if(partyList.size()>=1){
            partyvalue=partyMapper.update(party);
        }else{
            partyvalue=-1;
        }
        return partyvalue;
    }
    @Override
    public int delete(Party party){
        int partyvalue=0;
        Party party1=new Party();
        party1.setId(party.getId());
        List<Party> partyList=new ArrayList<>();
        partyList=selectByUserId(party1);
        if(partyList.size()>=1){
            partyvalue=partyMapper.delete(party);
        }else{
            partyvalue=-1;
        }
        return partyvalue;
    }
}




